/**
 * \file ps2.h
 * \brief i8042 module syscall definitions
 * \author Corey Tabaka
 */

/*
   Copyright 2006 Corey Tabaka

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

#ifndef __MODULE_I8042_SYSCALL_H__
#define __MODULE_I8042_SYSCALL_H__

#include <syscall.h>

enum {
	SYSCALL_I8042=0x1001,
};

// Subfunctions for SYSCALL_I8042
enum {
	SYSCALL_I8042_QUERY,
	SYSCALL_I8042_REQUEST_OWNERSHIP,
	SYSCALL_I8042_RELEASE_OWNERSHIP,
	SYSCALL_I8042_PEEK_EVENT,
	SYSCALL_I8042_GET_EVENT,
};

enum {
	INPUT_EVENT_KEY,
	INPUT_EVENT_REL,
};

typedef struct {
	uint32 type;
	uint32 code;
	sint32 value;
} input_event_t;

#ifndef __IN_KERENL_MODULE__

#include "keytypes.h"

static inline bool i8042_query(void) {
	return syscall32(SYSCALL_I8042, SYSCALL_I8042_QUERY, 0xdeadbeef)
		== 0xfeedbeef;
}

static inline bool i8042_requestOwnership(void) {
	return (bool) syscall32(SYSCALL_I8042, SYSCALL_I8042_REQUEST_OWNERSHIP);
}

static inline bool i8042_releaseOwnership(void) {
	return (bool) syscall32(SYSCALL_I8042, SYSCALL_I8042_RELEASE_OWNERSHIP);
}

static inline bool i8042_peekEvent(input_event_t *event) {
	return (bool) syscall32(SYSCALL_I8042, SYSCALL_I8042_PEEK_EVENT, event);
}

static inline bool i8042_getEvent(input_event_t *event) {
	return (bool) syscall32(SYSCALL_I8042, SYSCALL_I8042_GET_EVENT, event);
}

#endif

#endif
